package com.dms.shanshan.util;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.junit.Test;
import org.w3c.dom.Document;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

public  class ReadHSSFExcel {
public static Map<String,Integer> readExcel(String filePath) throws IOException {
    Map<String,Integer> excelMap=new HashMap<>();
    int rowNum=XMLWriter.readRootRowNum();
    FileInputStream fileInputStream=new FileInputStream(filePath);
    Workbook workbook=new HSSFWorkbook(fileInputStream);
    Sheet sheet=workbook.getSheetAt(0);
    Row row=sheet.getRow(0);
    for (int i=0;i<sheet.getRow(rowNum).getLastCellNum();i++){
         excelMap.put(sheet.getRow(rowNum).getCell(i).getStringCellValue(),i);
    }
    return excelMap;
}


    public static void main(String[] args) {
        System.out.println(XMLWriter.readRootRowNum());
    }
}
